package com.fengweijie.controller;

import com.fengweijie.entity.TProduct;
import com.fengweijie.service.ProductService;
import com.fengweijie.util.Result;
import com.fengweijie.util.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/product/api")
@CrossOrigin
@Slf4j
public class ProductController {

    @Autowired
    private ProductService productService;

    @PostMapping("/uploadNewProduct")
    public Result uploadNewProduct(@RequestBody TProduct tProduct) throws IOException {
        productService.uploadNewProduct(tProduct);
        return new Result(ResultCode.success,"新增成功",null);
    }

    @GetMapping("/getAllProducts")
    public Result getAllProducts(){
        List<TProduct> products = productService.getAllProducts();
        return new Result(ResultCode.success,null,products);
    }
}
